// Learn TypeScript:
//  - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html

const {ccclass, property} = cc._decorator;

@ccclass
export default class NewClass extends cc.Component {

    @property(cc.Sprite)
    icon: cc.Sprite = null;

    @property(cc.Slider)
    size:cc.Slider = null;

    @property([cc.Slider])
    RGBSliders: cc.Slider[] = [];

    start () {
        this.RGBSliders.forEach(value=>{
            value.progress = 1.;
        });
        this.size.progress = 0.15;

        this.updateMaterial();
    }

    onSliderEvent(slider: cc.Slider) {
        let label = slider.node.getChildByName("value").getComponent(cc.Label);
        label.string = `${slider.progress.toFixed(2)}`;
        this.updateMaterial();
    }
    updateMaterial() {
        let spriteMaterial = this.icon.getMaterial(0);
        // spriteMaterial.define("", true);
        spriteMaterial.setProperty("glowColorSize", cc.misc.clampf(this.size.progress, 0.02, 1));
        spriteMaterial.setProperty("glowColor", new cc.Vec4(this.RGBSliders[0].progress, this.RGBSliders[1].progress, this.RGBSliders[2].progress, 1));
    }
    // update (dt) {}
}
